package com.clothing.customization.controller.admin;

import com.clothing.customization.dto.ApiResult;
import com.clothing.customization.dto.MaterialInventoryDTO;
import com.clothing.customization.dto.MaterialInventoryQueryDTO;
import com.clothing.customization.service.MaterialInventoryService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 面料库存控制器
 */
@RestController
@RequestMapping("/api/admin/material-inventory")
@RequiredArgsConstructor
@PreAuthorize("hasRole('ADMIN')")
public class MaterialInventoryController {
    
    private final MaterialInventoryService materialInventoryService;
    
    /**
     * 分页查询面料库存
     */
    @GetMapping
    public ResponseEntity<ApiResult<Page<MaterialInventoryDTO>>> getList(MaterialInventoryQueryDTO queryDTO) {
        return ResponseEntity.ok(ApiResult.success(materialInventoryService.getList(queryDTO)));
    }
    
    /**
     * 获取面料库存详情
     */
    @GetMapping("/{id}")
    public ResponseEntity<ApiResult<MaterialInventoryDTO>> getDetail(@PathVariable Long id) {
        return ResponseEntity.ok(ApiResult.success(materialInventoryService.getDetail(id)));
    }
    
    /**
     * 创建面料库存
     */
    @PostMapping
    public ResponseEntity<ApiResult<MaterialInventoryDTO>> create(@Valid @RequestBody MaterialInventoryDTO dto) {
        return ResponseEntity.ok(ApiResult.success(materialInventoryService.create(dto)));
    }
    
    /**
     * 更新面料库存
     */
    @PutMapping("/{id}")
    public ResponseEntity<ApiResult<MaterialInventoryDTO>> update(
            @PathVariable Long id, 
            @Valid @RequestBody MaterialInventoryDTO dto) {
        return ResponseEntity.ok(ApiResult.success(materialInventoryService.update(id, dto)));
    }
    
    /**
     * 删除面料库存
     */
    @DeleteMapping("/{id}")
    public ResponseEntity<ApiResult<Void>> delete(@PathVariable Long id) {
        materialInventoryService.delete(id);
        return ResponseEntity.ok(ApiResult.success());
    }
} 